
def eraseOverlapIntervals(intervals) -> int:
    if intervals == []: return 0
    ## 根据区间右端点排序
    intervals = sorted(intervals, key = lambda x: x[1])
    num = 0
    new_interval = intervals[0]     # 被选的最新区间
    for interval in intervals[1:]:
        if interval[0] < new_interval[1]:   # 如果重叠删除区间，删除数量+1
            num += 1
        else:   # 如果不重叠更新new_interval
            new_interval = interval
    return num

lli=[[1,3],[2,4],[3,5],[6,7]]
ans=eraseOverlapIntervals(lli)
print(ans)